<template>
  <div>
    <el-row>
      <el-col :span="20">
        {{ formSearch }}
        <el-form :inline="true" :model="formSearch" class="demo-form-inline">
          <el-form-item>
            <el-select clearable v-model="formSearch.online_status" placeholder="请选择设备状态">
              <el-option label="在线" :value="1"></el-option>
              <el-option label="离线" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select clearable v-model="formSearch.bind_status" placeholder="请选择设备绑定状态">
              <el-option label="未绑定" :value="0"></el-option>
              <el-option label="已绑定" :value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input clearable v-model="formSearch.name" placeholder="请输入设备名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="toSearch">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="4" style="text-align: right;">
        <el-button type="primary">录入</el-button>
      </el-col>
    </el-row>
    <!-- 第二行表格 -->
    <div class="table">
      <el-table :data="empData" style="width: 100%">
        <el-table-column type="index" :index="1" label="序号" width="60" align="center">
        </el-table-column>
        <el-table-column prop="serial_number" label="编号" width="100" align="center">
        </el-table-column>
        <el-table-column prop="name" label="名称" width="700">
        </el-table-column>
        <el-table-column prop="online_status" label="在线状态" align="center">
          <template v-slot="scope">
            {{ scope.row.online_status == 0 ? '离线' : '在线' }}
          </template>
        </el-table-column>
        <el-table-column prop="bind_status" label="绑定状态" align="center">
          <template v-slot="scope">
            {{ scope.row.bind_status == 0 ? '未绑定' : '已绑定' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { get } from '@/utils/request'
export default {
  data() {
    return {
      // 搜索表单
      formSearch: {},
      // 表格数据源
      empData: [],
      params: {
        page: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    // 去查询
    toSearch() {
      // 每次查询从第一页查询
      this.params.page = 1;
      this.getEmpData();
    },
    // 分页多条件获取设备数据
    async getEmpData() {
      // 判断条件存不存在 存在根据条件查询 不存在删除条件
      let temp = {
        ...this.params,
        ...this.formSearch
      }
      let res = await get('/device/pageQuery', temp);
      console.log(res, '获取响应');
      this.empData = res.data.list;
    }
  },
  created() {
    this.getEmpData();
  }
}
</script>
<style lang="scss" scoped></style>